const app = getApp()
Page({
  data: {
    cont: "",
    weeklist: "",
    colorArrays: ["#9b5de5", "#f15bb5", "#00bbf9", "#ffbe0b", "#fb5607", "#ff006e", "#8338ec", "#3a86ff"],
    DataList: []
  },
  onLoad: function () {
    console.log() 
    var e = wx.getStorageSync(app.globalData.key);
    if (e) {
      this.setData({
        DataList: e
      })
    } else {
      this.getToday()
    }
  },
  onPullDownRefresh: function () {

    wx.cloud.callFunction({
      name: 'getCoursebyID',
      data: {
        'xh': app.globalData.xh,
        'week': app.globalData.week
      }
    }).then(res => {
      const DataList = JSON.parse(res.result).content.list;
      console.log(this.data.DataList)
      if (DataList.length == 0 || DataList == null) {
        wx.showToast({
          title: "没有课哦",
          icon: "none"
        });
      } else {
        wx.setStorageSync(app.globalData.key, DataList)
        this.setData({
          DataList
        })
        wx.showToast({
          title: "获取成功"
        });
      }
      wx.stopPullDownRefresh()
    }).catch(err => {
      console.log(err)
    })
  },
  onShareAppMessage: function () {
    return {
      title: "邀您使用",
      desc: "「工程课表」提供工程职院在校生师生课表等查询服务。",
      path: "/pages/index/index"
    }
  },
  showCardView: function (res) {
    var a = this.data.DataList.filter((function (t) {
      return t.id === res.currentTarget.dataset.id
    }))
    var n = a[0];
    wx.showModal({
      title: n.courseName,
      showCancel: !1,
      content: n.teacherName + "-" + n.classroomName
    })
  }
})